package com.zhiche.lisa.bms.controller.capital;


import com.zhiche.lisa.bms.service.capital.CapitalArrDtlService;
import com.zhiche.lisa.core.enums.CommonEnum;
import com.zhiche.lisa.core.supports.BaseException;
import com.zhiche.lisa.core.supports.RestfulResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 排款计划明细表新 前端控制器
 * </p>
 *
 * @author liuanshun
 * @since 2018-12-17
 */
@RestController
@RequestMapping("/capitalArrDtl")
@Api(value = "/capitalArrDtl", description = "排款计划明细接口", tags = {"排款计划明细接口"})
public class CapitalArrDtlController {
    private static Logger LOGGER = LoggerFactory.getLogger(CapitalArrDtlController.class);

    @Autowired
    private CapitalArrDtlService capitalArrDtlService;

    @PostMapping(value = "/updateStateByFcPay")
    @ApiOperation(value = "根据排款计划id更新明细的万金油审核状态", notes = "根据排款计划id更新明细的万金油审核状态", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiResponses({@ApiResponse(code = 0, message = "success"), @ApiResponse(code = -1, message = "系统异常")})
    public RestfulResponse<String> updateStateByFcPay(@RequestBody List<Long> headId) {
        LOGGER.info("/CapitalArrangementController.updateStateByFcPay Param {} ", headId);
        RestfulResponse<String> restful = new RestfulResponse<>(CommonEnum.SUCCESS.getCode(), CommonEnum.SUCCESS.getText(), null);
        try {
            capitalArrDtlService.updateStateByFcPay(headId);
        } catch (BaseException e) {
            LOGGER.error("/CapitalArrangementController.updateStateByFcPay ERROR: {}", e.getMessage());
            restful = new RestfulResponse(CommonEnum.ERROR.getCode(), e.getMessage(), null);
        } catch (Exception e) {
            LOGGER.error("/CapitalArrangementController.updateStateByFcPay ERROR: {}", e.getMessage());
            restful = new RestfulResponse(CommonEnum.ERROR.getCode(), CommonEnum.ERROR.getText(), null);
        }
        return restful;
    }
}

